package com.tao.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.tao.service.ArticleService;
import com.tao.service.impl.ArticleServiceImpl;
import com.tao.to.KArticleTO;
import com.tao.to.KCategoryTO;

@Controller
public class TaoController {

	private ArticleService articleService;
	
	public TaoController() {
		this.articleService = ArticleServiceImpl.getIntance();
	}
	
	
	@RequestMapping(value = "/index")
	public String userIpnSuccess(HttpServletRequest request,ModelMap modelMap) {

		List<KCategoryTO> categories = articleService.getCategoryList();
		for(KCategoryTO item : categories){
			List<KArticleTO> articles = articleService.getArticlesByCategory(item.getCategoryId());
			item.setArticleList(articles);
		}
		
		
		modelMap.addAttribute("categories", categories);
		return "index";
	}
	
	@RequestMapping(value = "/{catType}/{id}", method = RequestMethod.GET)
	public String historyDetail(Model model, @PathVariable String catType, @PathVariable long id, Pageable p) {
//	Page<SyncJobDetail> page = this.repo.findBySyncJobIdOrderByLastUpdateDesc(id, p);
//	model.addAttribute("page", page);
	return "historyDetail";
	}
}
